<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php $this->load->view(TPL_FOLDER."header");?>
<script type="text/javascript" src="{root_path}js/My97DatePicker/WdatePicker.js" charset="gb2312"></script>
<style type="text/css">
	.trtoggle td{ border-bottom: 1px dashed #CCCCCC}
	fieldset{ border-color:#FF9900}
	.border-btm td{ border-bottom:1px dashed #D2D2D2}
</style>
<table width="100%" border="0" cellpadding="5" cellspacing="0" >
  <tr>
    <td width="3%" align="left" ><img src="{tpl_path}images/forward.jpg" /></td>
    <td width="97%" align="left" >您现在的位置：<a href="<?php echo site_url(CTL_FOLDER."order");?>">全部订单</a> </td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-bottom:solid 1px #3C4952; margin-bottom:5px; margin-top:5px">
  <tr>
    <td height="24" align="left" ><form method="get">
        <input type="text" name="s_keyword" id="s_keyword" size="10">
        &nbsp;从
        <input type="text" name="s_date" id="s_date" size="15" onClick="WdatePicker({'dateFmt':'yyyy-MM-dd HH:mm:ss'})">
        &nbsp;到
        <input type="text" name="e_date" id="e_date" size="15" onClick="WdatePicker({'dateFmt':'yyyy-MM-dd HH:mm:ss'})">
        &nbsp;
        <input type="submit" name="s_sb" value="搜索" class="button-style2">
      </form>
      <?php foreach($order_nav->result() as $row)
	{
		if($row->status == 1)
		{
		echo "<a href='".site_url(CTL_FOLDER."order/")."?status={$row->status}'>已处理(".$row->snum.")</a> | ";
		}
		else
		{
			echo "<a href='".site_url(CTL_FOLDER."order/")."?status={$row->status}'>未处理(".$row->snum.")</a> | ";	
		}
	}
	?>
    </td>
  </tr>
</table>
<form method="post" name="list_form" id="list_form">
  <table width="100%" cellspacing="0" class="widefat">
    <thead>
      <tr id="trth">
        <th width="3%"><input type="checkbox" onclick="check_box(this.form.rd_id)" /></th>
        <th width="12%">订单号</th>
        <th width="12%">客户</th>
        <th width="15%">电话</th>
        <th width="16%">email</th>
        <th width="11%">是否处理</th>
        <th width="18%" id="remark">备注</th>
        <th width="13%">操作</th>
      </tr>
    </thead>
    <tfoot>
    </tfoot>
    <tbody id="check_box_id">
      <?php foreach($query->result() as $row) {?>
      <tr>
        <td class="rdId"><input name="rd_id[]" type="checkbox" id="rd_id" value="<?php echo $row->id;?>"></td>
        <td><?php echo $row->trade_num;?></td>
        <td><?php echo $row->true_name;?></td>
        <td><?php echo $row->tel;?></td>
        <td><?php echo $row->email;?></td>
        <td><?php 
		if($row->status)
		{
		?>
        <img src="{tpl_path}images/yes.gif" onclick="ajax_toggle(this,<?php echo $row->id;?>,'<?php echo site_url(CTL_FOLDER."order/ajax_toggle");?>')" style="cursor:pointer" />
        <?php
		}
		else
		{
		?>
        <img src="{tpl_path}images/no.gif" onclick="ajax_toggle(this,<?php echo $row->id;?>,'<?php echo site_url(CTL_FOLDER."order/ajax_toggle");?>')" style="cursor:pointer" />
        <?php
		}
		?></td>
        <td><div class="celltext"><?php echo $row->remark;?></div></td>
        <td><a href="javascript:send_email('<?php echo $row->email;?>')">发邮件</a> | <a href="javascript:void(0)" class="trtoggle">+展开</a></td>
      </tr>
      <tr style="display:none">
        <td colspan="8" align="left">
        <fieldset>
        <table width="100%" border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td height="25" colspan="5"><b>客户订购的产品：</b> &nbsp; &nbsp; &nbsp; &nbsp;下单时间：<?php echo time_diff($row->create_date);?></td>
            </tr>
            <tr>
              <td width="19%" height="25" bgcolor="#AFAFAF">图片</td>
              <td width="41%" bgcolor="#AFAFAF">名称</td>
              <td width="13%" bgcolor="#AFAFAF">数量</td>
              <td width="13%" bgcolor="#AFAFAF">单价（￥）</td>
              <td width="14%" bgcolor="#AFAFAF">小计（￥）</td>
            </tr>
         <?php 
		$cart = get_cart_list($row->id);
		foreach($cart as $row1)
		{
		?>   
            <tr class="border-btm">
              <td><img src="{tpl_path}images/loading.gif" rel="<?php echo get_real_path($row1->pic_path);?>" class="jq_pic_loading_80"  /></td>
              <td><?php echo $row1->title;?></td>
              <td><?php echo $row1->quantity;?></td>
              <td><?php echo $row1->price;?></td>
              <td><?php echo $row1->subtotal;?></td>
            </tr>
       <?php 
	   }?>     
       <tr>
              <td align="right">&nbsp;</td>
              <td align="right">&nbsp;</td>
              <td align="right">&nbsp;</td>
              <td align="right">总额：</td>
              <td><?php echo $row->total_price;?></td>
       </tr>
          </table>
          <div style="margin:10px 0; padding:10px 0px">
          <b>地址：</b><?php echo $row->address;?><br /><br />
          <b>客户留言：</b>
            <?php echo format_textarea($row->detail);?></div>
          </fieldset>            </td>
      </tr>
      <?php }?>
    </tbody>
  </table>
  <table width="100%" border="0" cellspacing="0" cellpadding="0" >
    <tr>
      <td style="padding-top:5px"><select name="action_url" id="action_url">
          <option value="" style="color:#FF0000">-选择操作-</option>
          <option value="<?php echo site_url(CTL_FOLDER."order/del_record");?>">删除</option>
        </select>
        &nbsp;
        <input type="button" name="submit_list_button" class="button-style2" onclick="submit_list_form(this.form,this)" id="submit_list_button" value="执行操作" />
        <img src="{tpl_path}images/notice.gif" class="tooltips" title="操作步骤：在左边勾选要操作的记录-->选择需要执行的操作-->点击“执行操作”按钮-->完成。" /> </td>
      <td align="right"><?php echo $paginate;?></td>
    </tr>
  </table>
</form>
<div id="div_dialog" style="display:none">
<form method="post" id="email_form" action="<?php echo site_url(CTL_FOLDER.'order/send_email');?>">
  <table width="100%"  border="0" cellpadding="3" cellspacing="0" >
    <tr>
      <td>邮件主题：</td>
      <td><input type="text" name="subject" size="60" maxlength="100" dataType="Require" msg="该项必填"/></td>
    </tr>
    <tr>
      <td>邮件正文：</td>
      <td><textarea name="content" cols="60" rows="8" datatype="Limit" msg="字数5-1000" min="5" max="1000"></textarea></td>
    </tr>
  </table>
  <input type="hidden" name="email" id="email" />
  </form>
</div>
<script language="javascript">
$(function(){
	$(".jq_pic_loading_80").each(function(){
		LoadImage($(this),$(this).attr("rel"),80);
	});
	$("a.trtoggle").toggle(function(){
		$(this).parent().parent().next("tr").show();
		$(this).html('-关闭');
	},function(){
		$(this).parent().parent().next("tr").hide();
		$(this).html('+展开');
	});
	$("div.celltext").edit_table({
		param:{'table':'weisu_order'}
	});
	$("#check_box_id tr").unbind('mouseover').unbind('mouseout');
	$("#check_box_id tr:even").css("background-color","#FFFFFF");
	$("#check_box_id td").css({'border-bottom':'1px dashed #D2D2D2'});
});
function submit_email_form()
{
	var theform = document.getElementById('email_form');
	if( ! Validator.Validate(theform,3)) return ;
	theform.submit();
}
function send_email(e){
	if( ! e)
	{
		alert('客户email有误');
		return;
	}
	document.getElementById('email').value = e;
	$('#div_dialog').dialog({  
		hide:'',   
		autoOpen:false,
		width:650,
		height:350, 
		modal:true, //蒙层  
		title:'发送邮件', 
		close: function(){ 
		},  
		overlay: {  
			opacity: 0.5, 
			background: "black"
		},  
		buttons:{  
			'取消':function(){$(this).dialog("close");},
			'发信':function(){submit_email_form();}  
		}
	});
	$('#div_dialog').dialog('open');
}	
</script>
<?php $this->load->view(TPL_FOLDER."footer");?>
